<?php


namespace app\admin\model;


use think\Model;

class Plan extends Model
{
	protected $createTime = "plan_time";
	protected $rate_rate2="0.0037";
	protected $rate_rate7="0.0055";
	//统计还款总交易量
	public function totalWithDraw(){
		$total = 0;
		$where=[];
		$where[]=["plan_state","=","1"];
		$where[]=["plan_type","=","1"];
		$total = $this->where($where)->sum("plan_money");
		return $total;
	}

	//统计还款总手续费
	public function totalWithDrawFee(){

	}


	//统计消费总交易量
	public function totalPay($pay_id=0){
		$total = 0;
		$where=[];
		$where[]=["plan_state","=","1"];
		$where[]=["plan_type","=","2"];
		if($pay_id>0){
			$where[]=["plan_pay_id","=",$pay_id];
		}
		$query_date = input('query_date', '', 'trim,htmlspecialchars');
		if (!empty($query_date)) {
			$query_date = explode(" - ", $query_date);
			$query_date[1] = date("Y-m-d", strtotime($query_date[1] . "+1day"));
			$where[]=["plan_pay_time","between",$query_date];
		}
		$total = $this->where($where)->sum("plan_money");
		return $total;
	}

	//统计消费总手续费
	public function totalPayFee($pay_id=0){
		$total = 0;
		$where=[];
		$where[]=["plan_state","=","1"];
		$where[]=["plan_type","=","2"];
		if($pay_id>0){
			$where[]=["plan_pay_id","=",$pay_id];
		}
		$query_date = input('query_date', '', 'trim,htmlspecialchars');
		if (!empty($query_date)) {
			$query_date = explode(" - ", $query_date);
			$query_date[1] = date("Y-m-d", strtotime($query_date[1] . "+1day"));
			$where[]=["plan_pay_time","between",$query_date];
		}
		$total1 = $this->where($where)->sum("plan_fee");
		$total2 = $this->where($where)->sum("plan_fee2");
		$total = $total1+$total2;
		return $total;
	}

	//统计消费手续费总利润
	public function totalPayFeeProfit(){
		$total=$this->totalPayFee();
		$profitTotal = model("UserBonuslog")->caclPayTotalMoney();

		$total2=$this->totalPay(2);
		$cbTotal2 = round($total2*$this->rate_rate2,2);//halt($cbTotal2);

		$total7=$this->totalPay(7);
		$cbTotal7 = round($total7*$this->rate_rate7,2);
		$profit = $total-$profitTotal-$cbTotal2-$cbTotal7;
		return $profit;
	}
}